//
//  LYActiveMenu.m
//  lottery
//
//  Created by 赵国腾 on 16/6/11.
//  Copyright © 2016年 赵国腾. All rights reserved.
//

#import "LYActiveMenu.h"
#import "LYCover.h"

@implementation LYActiveMenu

+ (instancetype)activeMenu {
    
    return [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil].firstObject;
}

+ (instancetype)showInPoint:(CGPoint)point {
    
    LYActiveMenu *activeMenu = [LYActiveMenu activeMenu];
    
    activeMenu.center = point;
    
    [LYKeyWindow addSubview:activeMenu];
    
    return activeMenu;
}

- (IBAction)closeClick:(UIButton *)sender {
    
    if ([self.delegate respondsToSelector:@selector(activeMenuDidClickCloseBtn:)]) {
        
        [self.delegate activeMenuDidClickCloseBtn:self];
    }
    
//    [LYActiveMenu hideInPoint:CGPointMake(44, 44)];
}

+ (void)hideInPoint:(CGPoint)point completion:(void (^)())completion{

    for (UIView *view in LYKeyWindow.subviews) {
        
        if ([view isKindOfClass:[LYActiveMenu class]]) {
            
            [(LYActiveMenu *)view setupHideAnim:point completion:completion];
        }
    }
}

- (void)setupHideAnim:(CGPoint)point completion:(void (^)())completion{
    
    [UIView animateWithDuration:0.25 animations:^{
        
        self.center = point;
        self.transform = CGAffineTransformMakeScale(0.1, 0.1);
        
    }completion:^(BOOL finished) {
                
        [self removeFromSuperview];
        
        if (completion) {
            completion();
        }
    }];
}

@end





















